/**
 * class Jade.EmployeeFormPanel
 * @param {} conf
 */
Jade.EmployeeFormPanel = function(conf){
	Ext.apply( this , conf );
	var self = this ;
	//供应商FormPanel
	Jade.EmployeeFormPanel.superclass.constructor.call( this , {
		labelWidth : 90, 
		border:false,
		bodyStyle : 'margin:0;padding:0;',
		autoScroll : true,
		header : false,
		maskDisabled : false,
		waitMsgTarget : true,
		height : 300,
		labelAlign:'right',
		buttonAlign:'center',
		reader : Jade.data.Readers.employeeReader,
		items : [new Ext.Panel({
			layout : 'column',
			width:600,
			border:false,
		    defaults:{border:false},
			autoHeight : true,
			items : [{
				columnWidth : .5,
				layout : 'form',
				items : [{
					xtype : 'hidden',
					name : 'id'
					},new Ext.form.TextField({
					fieldLabel : '员工编号<font color=red>*</font>',
					name : 'code',
					allowBlank : false,
					anchor : '90%',
					maxLength : 16
				}),new Ext.form.TextField({
					fieldLabel : '员工姓名<font color=red>*</font>',
					name : 'name',
					allowBlank : false,
					anchor : '90%',
					maxLength : 32
				}),new Ext.form.TextField({
					fieldLabel : '部门',
					name : 'department',
					anchor : '90%',
					maxLength : 32
				}),new Ext.form.TextField({
					fieldLabel : '职务',
					name : 'job',
					anchor : '90%',
					maxLength : 32
				})]
			}, {
				columnWidth : .5,
				layout : 'form',
				items : [new Ext.form.TextField({
					fieldLabel : '联系电话',
					name : 'phoneNo',
					anchor : '90%',
					maxLength : 20
				}),new Ext.form.TextField({
					fieldLabel : '手机号码',
					name : 'mobileNo',
					anchor : '90%',
					maxLength : 20
				}),new Ext.form.TextField({
					fieldLabel : '电子邮箱',
					name : 'email',
					anchor : '90%',
					maxLength : 32
				}),new Ext.form.Checkbox({
					fieldLabel : '是否禁用',
					name : 'unused',
					anchor : '90%',
					inputValue : '1'
				})]
			}]
		})]
	});
};
Ext.extend( Jade.EmployeeFormPanel, Ext.form.FormPanel,{});

/**
 * class EmployeeWindow 
 * @param {} conf
 */
Jade.EmployeeWindow = function(conf){
	Ext.apply( this, conf );
	var self = this; 
	this.formPanel = new Jade.EmployeeFormPanel({parent:this}) ;
	this.formPanel.region = 'center';
	this.noEditFields = this.formPanel.noEditFields;	// no edit fields
	
	this.saveButton = new Ext.Button({
		text : '保存',
		disabled : false,
		cls:'Mod',
		scope : this,
		handler : function() { this.save();}
	});
	
	this.cancelButton = new Ext.Button({
		text : '取消',
		handler : function() {
			self.hide();
			self.fireEvent('cancel');
		}
	});
	
	Jade.EmployeeWindow.superclass.constructor.call( this, {
		layout : 'border',
		width : 662,
		height: 250,
		closeAction : 'hide',
		items : [this.formPanel],
		plain : true,
		title : '员工档案',
		buttonAlign : 'center',
		modal : true,
		buttons : [this.saveButton,this.cancelButton]
	});
	
	this.save = function() {
		self.formPanel.form.submit( {
			url : '/base/employee.do?method=save',
			success : function(form, action) {
				messageloaded("保存成功");
				self.hide();
				self.fireEvent('aftersave', {
					code : form.findField('code').getValue(),
					name : form.findField('name').getValue()
				});
			},
			failure : function(form, action) {
				var msg = "保存失败!";
				displayMessageBox('提示', action.result.message);
				self.hide();
			}
		});
	};

	//查看window窗口
	this.showWindow = function( record ){
		self.show();
		if(record){
			self.formPanel.getForm().loadRecord(record);
		}else{
			self.formPanel.getForm().reset();
		}
	};
	
	//对组建增加事件
	this.addEvents('aftersave','cancel');
	
};

Ext.extend( Jade.EmployeeWindow, Ext.Window, {});




